package cate.game.pvp.minecraft.data;

import cate.common.table.pvp.minecraft.MinecraftExcel;
import cate.common.table.pvp.minecraft.mine_area_base.MinecraftMineAreaBaseRow;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@NoteClass("矿洞争霸-单层数据")
public class MinecraftLayerData {
    @NoteField("当前层")
    public int layer;
    @NoteField("点位数据")
    public Map<Integer, MinecraftCollectionPointData> layerPoints;

    public MinecraftLayerData() {

    }

    public MinecraftLayerData(int layer) {
        this.layer = layer;
    }

    public void init(MinecraftExcel minecraft) {
        if (layerPoints == null) {
            layerPoints = new HashMap<>();
        }
        List<MinecraftMineAreaBaseRow> rows = minecraft.mine_area_base.rowsByLayer.get(layer);
        if (rows == null) {
            layerPoints.clear();
            return;
        }
        layerPoints.entrySet().removeIf(entry -> rows.stream().noneMatch(row -> row.id == entry.getKey()));
        for (MinecraftMineAreaBaseRow row : rows) {
            if (!layerPoints.containsKey(row.id)) {
                layerPoints.put(row.id, new MinecraftCollectionPointData(layer, row.id));
            }
        }
        layerPoints.values().forEach(MinecraftCollectionPointData::init);
    }
}
